/*
 * Project : Linuxbox
 * File    : UserManAdd.java
 * Version : 1.0
 * Author  : Kevin Zhang
 *
 * Copyright (c) 2000-2001 by Linuxbox, Inc.
 * All rights reserved.
 */
package linuxbox.admin.servlet;

import javax.servlet.http.*;


import linuxbox.BoxStatic;
import linuxbox.admin.logic.*;
import linuxbox.common.*;

public class UserManAddAction extends Action {
	protected static String successJSP = null;
	protected static String check = "CHECKED";
	
    public void doAction(HttpSession aSession, BoxSession aBoxSession, 
    HttpServletRequest req, HttpServletResponse res) throws Exception {
		BoxStatic.logger.debug("I am in UserManAdd now ... ");
		
		String loginID = req.getParameter("LOGIN_ID");
		String password = req.getParameter("PASSWORD");			
		String firstName = req.getParameter("FIRST_NAME");
		String lastName = req.getParameter("LAST_NAME");
		String address = req.getParameter("ADDRESS");
		String city = req.getParameter("CITY");
		String state = req.getParameter("STATE");
		String zipcode = req.getParameter("ZIPCODE");
		String phone = req.getParameter("PHONE");
		String fax = req.getParameter("FAX");
		String mobile = req.getParameter("MOBILE");
		String email = req.getParameter("EMAIL");
		String managerID = req.getParameter("MANAGER_ID");
		String deptID = req.getParameter("DEPT_ID");
		String isManager = req.getParameter("IS_MANAGER");
		String note = req.getParameter("NOTE");
		String disable = req.getParameter("DISABLE");
		String noExpire = req.getParameter("NO_EXPIRE");

		String newsAdmin = req.getParameter("NEWS_ADMIN");
		String pollAdmin = req.getParameter("POLL_ADMIN");
		String resourceAdmin = req.getParameter("RESOURCE_ADMIN");
		String reservAdmin = req.getParameter("RESERV_ADMIN");
		String downloadAdmin = req.getParameter("DOWNLOAD_ADMIN");
		String bbsAdmin = req.getParameter("BBS_ADMIN");
		String userAdmin = req.getParameter("USER_ADMIN");

		BoxStatic.logger.debug("loginID is " + loginID);
		BoxStatic.logger.debug("password is " + password);
		BoxStatic.logger.debug("firstName is " + firstName);
		BoxStatic.logger.debug("lastName is " + lastName);
		BoxStatic.logger.debug("note is " + note);
		BoxStatic.logger.debug("disable is " + disable);
		BoxStatic.logger.debug("noExpire is " + noExpire);
		
		long right1 = UserRights.NOMAL_USER;
		BoxStatic.logger.debug("User rights is " + Long.toHexString(right1));
		
		if (check.equals(newsAdmin)) {
		    right1 = UserRights.setNewsAdmin(right1);
		}

		if (check.equals(pollAdmin)) {
		    right1 = UserRights.setPollAdmin(right1);
		}

		if (check.equals(resourceAdmin)) {
		    right1 = UserRights.setResourceAdmin(right1);
		}

		if (check.equals(reservAdmin)) {
		    right1 = UserRights.setReservationAdmin(right1);
		}

		if (check.equals(downloadAdmin)) {
		    right1 = UserRights.setDownloadAdmin(right1);
		}
		BoxStatic.logger.debug("User rights is " + Long.toHexString(right1));
		 
		if (check.equals(bbsAdmin)) {
		    right1 = UserRights.setBBSAdmin(right1);
		}
		BoxStatic.logger.debug("User rights is " + Long.toHexString(right1));

		if (check.equals(userAdmin)) {
		    right1 = UserRights.setUserAdmin(right1);
		}
		BoxStatic.logger.debug("User rights is " + Long.toHexString(right1));

		User user = new User(loginID, password, firstName, lastName, 
			right1, 0, check.equals(noExpire));
			
		user.setAddress(address);
		user.setCity(city);
		user.setState(state);
		user.setZipCode(zipcode);
		user.setPhone(phone);
		user.setFax(fax);
		user.setMobile(mobile);
		user.setEmail(email);
		
		if (managerID != null && !"".equals(managerID))
			user.setManagerID(Integer.parseInt(managerID));
		
		if (deptID != null && !"".equals(deptID))
			user.setDeptID(Integer.parseInt(deptID));
			
		user.setIsManager(check.equals(isManager));	
		user.setDisable(check.equals(disable));	
		user.setNote(note);			

		UserManager um = UserManager.getInstance();
		um.addUser(user);
		redirectFile(successJSP, req, res);
		BoxStatic.logger.debug("I am leaving UserManAdd now ... ");
	}

	public void setSuccessJSP(String str) {
	    //"/linuxbox/jsp/admin/UserManager.jsp"
		successJSP = str;
	}
}
